package com.pikaqiu.warehouse.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.pikaqiu.warehouse.utils.DateUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisPlusAutoFillConfig implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        Object createDate = getFieldValByName("createDate", metaObject);
        if (createDate == null) {
            setFieldValByName("createDate", DateUtils.date(), metaObject);
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        Object updateDate = getFieldValByName("updateDate", metaObject);
        if (updateDate == null) {
            setFieldValByName("updateDate", DateUtils.date(), metaObject);
        }
    }

}
